package forum.server.controller;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * This class encapsulates the Java Logger.
 * Provides logging functionality to predefined file, in various levels.
 * Implemented as Singleton.
 * @author Mirsky
 */
public class MyLogger {
	
	private static MyLogger instance = null;
	private static Logger logger = null;
	
	private MyLogger() {
		logger = Logger.getLogger("forum.log");
	}
	
	/**
	 * @return an instance of this class.
	 */
	public static MyLogger getInstance() {
		if (instance == null)
			instance = new MyLogger();
		return instance;
	}
	
	/**
	 * Logs the msg at Fine level (i.e. Debugging msgs).
	 * @param msg the message to log
	 */
	public void logFine(String msg) {
		logger.log(Level.FINE, msg);
	}

	/**
	 * Logs the msg at Info level (i.e. Users actions).
	 * @param msg the message to log
	 */	
	public void logInfo(String msg) {
		logger.log(Level.INFO, msg);		
	}
	
	/**
	 * Logs the msg at Severe level (i.e. Errors and anomalies).
	 * For Exceptions logging please use the logException() method.
	 * @param msg the message to log
	 */	
	public void logSevere(String msg) {
		logger.log(Level.SEVERE, msg);
	}	
	
	/**
	 * Used to log exceptions.
	 * @param msg the message to log
	 * @param thrown the exception to log
	 */
	public void logException(String msg, Throwable thrown) {
		logger.log(Level.SEVERE, msg, thrown);
	}
}
